from app.database.connector import Database
from app.database.dao import BaseDAO

class UserService:
    def __init__(self):
        self.user_dao = BaseDAO('users')

    def get_profile(self, user_id):
        user = self.user_dao.find_by_id(user_id)
        if user:
            return {"username": user['username'], "email": user['email']}
        return {"error": "User not found"}

    def get_user_list(self, page=1, page_size=10):
        """
        获取用户列表
        :param page: 页码，默认为1
        :param page_size: 每页数量，默认为10
        :return: 用户列表数据
        """
        skip = (page - 1) * page_size
        users = self.user_dao.find_all(skip=skip, limit=page_size)
        return users

    def create_user(self, data):
        return self.user_dao.create(data)

    def update_user(self, user_id, data):
        return self.user_dao.update(user_id, data)

    def delete_user(self, user_id):
        return self.user_dao.delete(user_id)